<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="本地名称" prop="localName">
        <el-input
          v-model="queryParams.localName"
          placeholder="请输入苍穹名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="高德名称" prop="gaodeName">
        <el-input
          v-model="queryParams.gaodeName"
          placeholder="请输入高德名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上级长名称" prop="gaodeName">
        <el-input
          v-model="queryParams.lastFullName"
          placeholder="请输入上级长名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="对照状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择对照状态" clearable size="small">
          <el-option
            v-for="dict in dzStatusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="parseInt(dict.dictValue)"
          />
        </el-select>
      </el-form-item>-->
      <!--<el-form-item label="对照日期" prop="createTime">
        <el-date-picker clearable size="small"
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择创建时间时间">
        </el-date-picker>
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
		  plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dz:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleDz"
        >手工对照</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh"
          size="mini"
        ><el-link
          type="info"
          @click="sendDzMessage">
        发送对照消息</el-link>
        </el-button>
      </el-col>

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dzList" @selection-change="handleSelectionChange"
              :height="this.tableHeight">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="苍穹名称" align="center" prop="localName" />
      <el-table-column label="高德名称" align="center" prop="gaodeName" />
      <el-table-column label="长名称" align="center" prop="fullName" />
      <el-table-column label="上级长名称" align="center" prop="lastFullName" />
      <el-table-column label="状态"    align="center" prop="status" :formatter="statusFormat"/>
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          &lt;!&ndash;<el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:dz:edit']"
          >修改</el-button>&ndash;&gt;
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:dz:remove']"
          >删除</el-button>
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改高德编码对照表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="本地编码" prop="localCode">
          {{form.localCode}}
        </el-form-item>
        <el-form-item label="本地名称" prop="localName">
          {{form.localName}}
        </el-form-item>
        <el-form-item label="高德编码" prop="gaodeCode">
          {{form.gaodeCode}}
        </el-form-item>
        <el-form-item label="高德名称" prop="gaodeName">
          {{form.gaodeName}}
        </el-form-item>
        <el-form-item label="对照状态" prop="status">
          <el-select v-model="form.status" disabled placeholder="请选择对照状态" clearable size="small">
            <el-option
              v-for="dict in dzStatusOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="form.status"
            />
          </el-select>
        </el-form-item>
      </el-form>
<!--      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>-->
    </el-dialog>
  </div>
</template>

<script>
import { listDz, handleDz,sendDzMessage} from "@/api/integration/gaodeDz";

export default {
  name: "gaodeDz",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 高德编码对照表表格数据
      dzList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tableHeight : null,
      // 状态列表
      dzStatusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        localCode: null,
        localName: null,
        gaodeCode: null,
        gaodeName: null,
        fullName: null,
        lastFullName: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("gaodeDz_status").then(response => {
      this.dzStatusOptions = response.data;
    });
    this.tableHeight = (document.body.offsetHeight)-270
  },
  methods: {
    /** 查询高德编码对照表列表 */
    getList() {
      this.loading = true;
      listDz(this.queryParams).then(response => {
        this.dzList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 字典状态翻译区 */
    statusFormat(row, column) {
      return this.selectDictLabel(this.dzStatusOptions, row.status);
    },

    // 业务逻辑方法区
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: null,
        localCode: null,
        localName: null,
        gaodeCode: null,
        gaodeName: null
      };
      this.resetForm("form");
    },

    // 按钮区
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('webservice/dz/export', {
        ...this.queryParams
      }, `区划对照表.xlsx`)
    },
    /** 手工同步 */
    handleDz(){
      this.$confirm('是否手工同步高德对照表的数据?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return handleDz();
      }).then(() => {
        this.getList();
        this.msgSuccess("同步成功");
      })
    },
    /** 下载高德编码表操作 */
    sendDzMessage() {
      this.$confirm('是否发送对照消息?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
        }).then(function() {
          return sendDzMessage();
        }).then(() => {
          this.msgSuccess("发送成功");
      })
    },
  }
};
</script>
